# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/12 22:24
# @Author   : Robot-Zsj
"""
description:

i:
3
1 1 1
o:
0
"""
import bisect

n = int(input())
weights = list(map(int, input().split()))


def getResult():
    weights.sort()

    while len(weights) >= 3:
        z = weights.pop()
        y = weights.pop()
        x = weights.pop()

        remain = abs((z - y) - (y - x))

        if remain != 0:
            idx = bisect.bisect(weights, remain)

            weights.insert(idx, remain)

    if len(weights) == 0:
        return 0

    else:
        return max(weights)


print(getResult())
